<?php
    header("Content-type:text/html;charset=utf-8");
    date_default_timezone_set('PRC');
    ini_set("display_errors", "On");
    error_reporting(E_ALL | E_STRICT);
    //error_reporting(0);
    require_once(dirname(__FILE__).'/common/config.php');
    write_log($_POST,'returl');
    /*充值状态*/
    $ret_code = isset($_POST['ret_code']) ? intval($_POST['ret_code']) : 0;
    /*订单单号*/
    $sporder_id = isset($_POST['sporder_id']) ? trim($_POST['sporder_id']) : '';
    /*处理时间*/
    $ordersuccesstime = isset($_POST['ordersuccesstime']) ? trim($_POST['ordersuccesstime']) : '';
    /*失败原因*/
    $err_msg = isset($_POST['err_msg']) ? trim($_POST['err_msg']) : '';
    /*官方订单号*/
    $gascard_code = isset($_POST['gascard_code']) ? trim($_POST['gascard_code']) : '';
    /*签名*/
    $sign = isset($_POST['sign']) ? trim($_POST['sign']) : '';
    /*查询订单是否存在*/
    $row = $rnpdo->RnFetchRow("select id,sporder_id,game_state,goodstype,cardnum,cardid,game_userid from {$ritesLog} where sporder_id=:sporder_id order by id DESC limit 1 ",array('sporder_id'=>$sporder_id));
    if(empty($row['errmsg']))
    {
    	exit('订单不存在！');
    }
    /*订单信息*/
    $order_info = $row['errmsg'];
    $goodstype = $order_info['goodstype'];
    /*手机充值*/
    if($goodstype == 1)
    {
        require_once(dirname(__FILE__).'/common/mobilerecharge.php');
        /*实例化充值类*/
        $recharge = new mobilerecharge();
        $check_res = $recharge->checkSign($order_info['game_userid'],$order_info['sporder_id'],$order_info['cardnum'],$order_info['cardid'],$sign);
        /*日志类型*/
        $log_type = 'mobilereb';
        if(!$check_res)
        {
        	exit('签名错误！');
        }
    }
    /*游戏充值*/
    elseif($goodstype == 2)
    {
        require_once(dirname(__FILE__).'/common/gamerecharge.php');
        /*实例化充值类*/
        $recharge = new gamerecharge();
        $check_res = $recharge->checkSign($order_info['game_userid'],$order_info['sporder_id'],$order_info['cardnum'],$order_info['cardid'],$sign);
        /*日志类型*/
        $log_type = 'gamereb';
        if(!$check_res)
        {
        	exit('签名错误！');
        }
    }
    write_log($_POST,$log_type);
    /*修改订单状态*/
    if($order_info['game_state'] != 1)
    {
    	$arr = array(
    		'game_state'=>$ret_code,
    		'ordersuccesstime'=>$ordersuccesstime,
    		'err_msg'=>$err_msg,
    		'sporder_id'=>$sporder_id
    	);
    	$res = $rnpdo->RnPtmQuery("update {$ritesLog} set game_state=:game_state,ordersuccesstime=:ordersuccesstime,err_msg=:err_msg where sporder_id=:sporder_id ", $arr);
    }
    /*发送短信*/
    require_once(dirname(__FILE__).'/common/sms.php');
    $SendSms = new SendSms();
    $mobile        = '15829337275'; //接收短信的手机号码
    $boc           = 'SN'; //行标示
    $salt          = 'OISIOFIOSL'; //约定生成签名的盐值
    $signName      = '闰能科技'; //短信签名
    $templateCode  = 'SMS_152284975'; //短信模板ID
    $templateParam = array('info' => '测试', 'remark' => '警戒值'); //短信模板参数，数组键名必须与短信模板中的变量名一致
    $remark        = '测试'; //备注，用于区分活动
    $result        = $SendSms->requestApi($mobile, $boc, $salt, $signName, $templateCode, $templateParam, $remark); //调用SendSms的requestApi方法发送短信
    print_r($result); //打印发送结果信息